define(function (require, exports) {
  exports.ready = function (hashCode, data, cite) {
    yufp.custom.vue({
      el: cite.el,
      data: function () {
        var poolId = data.poolId;
        return {
          urls: {
            index: backend.workflowService + '/api/bench/todo',
            signIn: backend.workflowService + '/api/core/signTaskPool'
          },
          tableColumns: [
            { label: '流程实例号', prop: 'instanceId', resizable: true, align: 'center' },
            { label: '流程名称', prop: 'flowName', resizable: true, hidden: true, align: 'center' },
            { label: '流程id', prop: 'flowId', resizable: true, hidden: true },
            { label: '流程管理员', prop: 'flowAdmin', resizable: true, hidden: true },
            { label: '流程发起者', prop: 'flowStarter', resizable: true, hidden: true },
            { label: '流程发起时间', prop: 'startTime', resizable: true, hidden: true },
            { label: '系统id', prop: 'systemId', resizable: true, hidden: true },
            { label: '发起人机构id', prop: 'orgId', resizable: true, hidden: true },
            { label: '流程状态', prop: 'flowState', resizable: true, hidden: true },
            { label: '业务流水号', prop: 'bizId', resizable: true, align: 'center' },
            { label: '客户id', prop: 'bizUserId', resizable: true, align: 'center' },
            { label: '客户名称', prop: 'bizUserName', resizable: true, align: 'center' },
            { label: '当前节点ID', prop: 'nodeId', resizable: true, hidden: true },
            { label: '当前节点', prop: 'nodeName', resizable: true, align: 'center' },
            { label: '节点处理人', prop: 'userId', resizable: true, hidden: true },
            { label: '当前处理人', prop: 'userName', resizable: true, align: 'center' },
            { label: '开始时间', prop: 'startTime', resizable: true, align: 'center' },
            { label: '上一节点', prop: 'lastNodeId', resizable: true, hidden: true },
            { label: '上一节点', prop: 'lastNodeName', resizable: true, align: 'center', hidden: true },
            { label: '上一节点处理人', prop: 'lastUserId', resizable: true, hidden: true },
            { label: '上一处理人', prop: 'lastUserName', resizable: true, align: 'center', hidden: true },
            {
              label: '上一节点审批结果',
              prop: 'nodeState',
              resizable: true,
              align: 'center',
              template: function () {
                return '<template scope="scope">\
                <span style="color:gray;" v-if="scope.row.nodeState==\'O-0\'">拿回</span>\
                <span style="color:red;" v-if="scope.row.nodeState==\'O-1\'">打回</span>\
                <span style="color:orange;" v-if="scope.row.nodeState==\'O-2\'">退回</span>\
                <span style="color:gray;" v-if="scope.row.nodeState==\'O-3\'">挂起</span>\
                <span style="color:gray;" v-if="scope.row.nodeState==\'O-4\'">唤醒</span>\
                <span style="color:gray;" v-if="scope.row.nodeState==\'O-5\'">催办</span>\
                <span style="color:gray;" v-if="scope.row.nodeState==\'O-6\'">转办</span>\
                <span style="color:gray;" v-if="scope.row.nodeState==\'O-7\'">协办</span>\
                <span style="color:gray;" v-if="scope.row.nodeState==\'O-9\'">跳转</span>\
                <span style="color:green;" v-if="scope.row.nodeState==\'O-12\'">同意</span>\
                <span style="color:gray;" v-if="scope.row.nodeState==\'O-15\'">撤回</span>\
                <span style="color:gray;" v-if="scope.row.nodeState==\'O-10\'">委托</span>\
                <span style="color:gray;" v-if="scope.row.nodeState==\'O-16\'">发起</span>\
                <span style="color:gray;" v-if="scope.row.nodeState==\'O-13\'">自动提交</span>\
                <span style="color:gray;" v-if="scope.row.nodeState==\'O-8\'">否决</span>\
                <span style="color:gray;" v-if="scope.row.nodeState==\'O-14\'">正常结束</span>\
                </template>';
              }
            },
            { label: '流程参数', prop: 'flowParam', resizable: true, hidden: true },
            { label: '业务类型', prop: 'bizType', resizable: true, align: 'center', hidden: true },
            {
              label: '操作',
              align: 'center',
              width: 100,
              fixed: 'right',
              template: function () {
                return '<template scope="scope">\
                <el-button size="small" @click="$emit(\'custom-row-op\',scope,\'edit\')">签收</el-button>\
                </template>';
              }
            }
          ],
          formdata: {},
          baseParams: {
            condition: JSON.stringify({
              userId: 'T.' + poolId,
              currentUserId: 'T.' + poolId
            })
          },
          height: yufp.frame.size().height - 103,
          poolId: poolId,
          currentOrgId: yufp.session.org.id,
          currentUserId: yufp.session.userCode,
          returnBackFuncId: '',
          returnBackRootId: ''
        };
      },
      mounted: function () { // 进入初始化
        this.poolId = data.poolId;
        this.returnBackFuncId = data.returnBackFuncId;
        this.returnBackRootId = data.returnBackRootId;
      },
      methods: {
        customRowOp: function (scope, op) {
          var _this = this;
          // 当前行号：scope.$index
          // 当前行数据：scope.row
          // 当前列对象：scope.column
          // this.$alert('你现在正在操作：' + op + '当前行ID值为：' + scope.row.flowId, '提示');
          if (op == 'edit') {
            _this.signIn(scope.row);
          }
        },
        signIn: function (row) { // 签收
          var _this = this;
          var param = {
            instanceId: row.instanceId,
            nodeId: row.nodeId,
            userId: yufp.session.userCode,
            poolId: _this.poolId
          };
          yufp.service.request({
            method: 'POST',
            data: param,
            url: _this.urls.signIn,
            callback: function (code, message, response) {
              if (response.code == 0) {
                _this.$message(response.data.tip);
                _this.$refs.reftable.remoteData();
              } else {
                _this.$message(response.message);
              }
            }
          });
        },
        backFn: function () {
          yufp.router.to(this.returnBackFuncId, null, this.returnBackRootId);
        },
        rowDblclick: function (row, event) { // 往实例信息页面跳转
          var param = {
            instanceId: row.instanceId,
            nodeId: row.nodeId,
            // userId: row.userId,
            returnBackFuncId: cite.id,
            returnBackRootId: cite.rootId
          };
          // yufp.router.to("instanceInfo",param,cite.rootId);
        }
      }
    });
  };
});
